package com.example.smg;

import com.example.contacts.*;

import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Contacts;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;


public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		
		
		ContentResolver contentresolver = this.getContentResolver() ;
		Cursor cur = contentresolver.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null) ;
		SmgSqliteOpenHelper sqliteopenhelper = new SmgSqliteOpenHelper( MainActivity.this , "Contacts", null,1);
		
		final SQLiteDatabase db = sqliteopenhelper.getWritableDatabase();
		//sqliteopenhelper.onCreate(db);
		final MyContacts contacts = new MyContacts();
		contacts.createMyDb(cur,db,contentresolver);
		
		
		//change
		
		
		Button button1 = (Button)findViewById(R.id.button1);
		
		button1.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				TextView textview1 = (TextView)findViewById(R.id.textView1);
				String group_name=textview1.getText().toString();
				contacts.createGroup(db, group_name);
			}
			
		});
		
		
		
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	


}
